//
//  SearchResultViewTableViewCell.swift
//  APP
//
//  Created by gy on 2022/3/23.
//

import UIKit

class SearchResultViewTableViewCell: UITableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        configUI()
    }
    func setInfo(title: String, imgUrl: String) {
        titleLabel.text = title
        imgView.sd_setImage(with: URL.encodedURL(string: imgUrl), placeholderImage: UIImage(named: "img_request_loading_amj"))
    }
    func setKeyword(_ keyword: String) {
        
        imgView.isHidden = true
        imgView.snp.updateConstraints { make in
            make.width.equalTo(0)
        }
        
        titleLabel.text = keyword
        titleLabel.snp.updateConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(0)
        }
    }
    
    // MARK: ---- configUI
    func configUI() {
        
        selectionStyle = .none
        contentView.addSubview(imgView)
        contentView.addSubview(titleLabel)
        contentView.addSubview(lineView)
        
        imgView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.top.equalTo(12)
            make.bottom.equalTo(-12)
            make.width.equalTo(60)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(10)
            make.centerY.equalTo(imgView)
            make.right.equalTo(-16)
        }
        lineView.snp.makeConstraints { make in
            make.bottom.right.equalToSuperview()
            make.left.equalTo(imgView)
            make.height.equalTo(CGFloat.app_lineHieght)
        }
    }
    private lazy var imgView: UIImageView = {
        let picView = UIImageView()
        picView.contentMode = .scaleAspectFill
        picView.clipsToBounds = true
        return picView
    }()
    private lazy var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.font = kSetPingFangRegular(14)
        return titleLabel
    }()
    private lazy var lineView: UIView = {
        let line = UIView()
        line.backgroundColor = .app_lineColor
        return line
    }()
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
